
class Broker(object):
    # 任务队列
    broker_list = []

class worker(object):
    # 任务执行者
    def __init__(self):
        self.broker = Broker()

    def run(self,broker,func):
        # for f in self.broker.broker_list:
        #     if f == func:
        if func in broker.broker_list:
            func()
        else:
             return 'error'

class Celery(object):
    def __init__(self):
        self.broker = Broker()
        self.worker = worker()

    def add(self,func):
        self.broker.broker_list.append(func)


    def work(self,func):
        self.worker.run(self.broker,func)


# 定义要执行的方法
def send_sms_code():
    print('send_sms_code')
# 客户端行为,生成对象
app = Celery()
# 添加任务
app.add(send_sms_code)
# 执行任务
app.work(send_sms_code)

